// 全局过滤函数
import * as Utils from "./index";
export function filter_price(val) {
  return "¥" + val;
}
export function filter_device_status(val) {
  const STATUS = { online: "在线", sell: "出售", unline: "离线", stop: "停售" };
  return STATUS[val];
}

export function modifyTime(param) {
  return Utils.parseTime(new Date(param));
}

/**
 * 用户类型（admin：监管管理员，hospital：医院管理员，staff：员工）
 * @param {*} val
 * @returns
 */
export function filter_user_type(val) {
  if (!val) return "-";
  switch (val) {
    case "admin":
      return "监管管理员";
    case "hospital":
      return "医院管理员";
    case "staff":
      return "员工";
  }
}

/**
 * 认证状态（wait：未认证，success：认证成功，fail：认证失败）
 * @param {*} data
 * @returns
 */
export function filter_credit_status(val) {
  if (!val) return "-";
  switch (val) {
    case "wait":
      return "未认证";
    case "success":
      return "认证成功";
    case "fail":
      return "认证失败";
  }
}
/**
 * 认证状态（wait：未认证，success：认证成功，fail：认证失败）
 * @param {*} data
 * @returns
 */
export function filter_credit_status_class(val) {
  if (!val) return "-";
  switch (val) {
    case "wait":
      return "warning";
    case "success":
      return "success";
    case "fail":
      return "danger";
  }
}
/**
 * 报警类型
 * @param {*} val
 * @returns
 */
export function filter_alarm_type(val) {
  if (!val) return "";
  switch (val) {
    case "out_depot_time_red":
      return "出库超时红色";
    case "out_depot_time_yellow":
      return "出库超时黄色";
    case "do_collect_weight_red":
      return "收集超重红色";
    case "do_collect_weight_yellow":
      return "收集超重黄色";
    case "in_depot_weight_red":
      return "入库超重红色";
    case "in_depot_weight_yellow":
      return "入库超重黄色";
    case "out_depot_weight_red":
      return "出库超重红色";
    case "out_depot_weight_yellow":
      return "出库超重黄色";
    case "do_collect_time_red":
      return "收集超时红色";
    case "do_collect_time_yellow":
      return "收集超时黄色";
    case "in_depot_time_red":
      return "入库超时红色";
    case "in_depot_time_yellow":
      return "入库超时黄色";
  }
}
/**
 * 报警类型图标
 * @param {*} val
 * @returns
 */
export function filter_alarm_type_img(val) {
  if (!val) return "";
  switch (val) {
    case "out_depot_time_red":
      return require("@/assets/time_red.png");
    case "out_depot_time_yellow":
      return require("@/assets/time_yellow.png");
    case "do_collect_weight_red":
      return require("@/assets/weight_red.png");
    case "do_collect_weight_yellow":
      return require("@/assets/weight_yellow.png");
    case "in_depot_weight_red":
      return require("@/assets/weight_red.png");
    case "in_depot_weight_yellow":
      return require("@/assets/weight_yellow.png");
    case "out_depot_weight_red":
      return require("@/assets/weight_red.png");
    case "out_depot_weight_yellow":
      return require("@/assets/weight_yellow.png");
    case "do_collect_time_red":
      return require("@/assets/time_red.png");
    case "do_collect_time_yellow":
      return require("@/assets/time_yellow.png");
    case "in_depot_time_red":
      return require("@/assets/time_red.png");
    case "in_depot_time_yellow":
      return require("@/assets/time_yellow.png");
  }
}

export function filter_diction(val) {
  switch (val) {
    case "gender":
      return "性别";
    case "waste_classify":
      return "医废分类";
    case "warn_classify":
      return "预警分类";
    case "warn_symbol":
      return "超重预警符号";
    case "warn_unit":
      return "超重预警单位";
    case "warn_weight_condition":
      return "条件";
    case "warn_weight_unit":
      return "单位";
  }
}

export function timeFn(d1) {
  //di作为一个变量传进来
  //如果时间格式是正确的，那下面这一步转化时间格式就可以不用了
  if (!d1) return;
  var dateBegin = new Date(d1.replace(/-/g, "/")); //将-转化为/，使用new Date
  var dateEnd = new Date(); //获取当前时间
  var dateDiff = dateEnd.getTime() - dateBegin.getTime(); //时间差的毫秒数
  var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)); //计算出相差天数
  var leave1 = dateDiff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
  var hours = Math.floor(leave1 / (3600 * 1000)); //计算出小时数
  //计算相差分钟数
  var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
  var minutes = Math.floor(leave2 / (60 * 1000)); //计算相差分钟数
  //计算相差秒数
  var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
  var seconds = Math.round(leave3 / 1000);
  if (dayDiff > 0) {
    return `${dayDiff}天${hours}小时${minutes}分钟${seconds}秒`;
  } else if (hours > 0) {
    return `${hours}小时${minutes}分钟${seconds}秒`;
  } else if (minutes > 0) {
    return `${minutes}分钟${seconds}秒`;
  } else {
    return `${seconds}秒`;
  }
}

export function timeFormat(value, format) {
  if (!value) return;
  let date = new Date(value);
  let y = date.getFullYear();
  let m = date.getMonth() + 1;
  let d = date.getDate();
  let h = date.getHours();
  let min = date.getMinutes();
  let s = date.getSeconds();
  let result = "";
  if (format == undefined) {
    result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
      h < 10 ? "0" + h : h
    }:${min < 10 ? "0" + min : min}:${s < 10 ? "0" + s : s}`;
  }
  if (format == "yyyy-mm-dd") {
    result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
  }
  if (format == "yyyy-mm-dd HH:mm") {
    result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d} ${
      h < 10 ? "0" + h : h
    }:${min < 10 ? "0" + min : min}`;
  }
  if (format == "yyyy/mm/dd") {
    result = `${y}-${m < 10 ? "0" + m : m}-${d < 10 ? "0" + d : d}`;
  }
  if (format == "yyyy-mm") {
    result = `${y}-${m < 10 ? "0" + m : m}`;
  }
  if (format == "mm-dd") {
    result = ` ${mm < 10 ? "0" + mm : mm}:${ddmin < 10 ? "0" + dd : dd}`;
  }
  if (format == "hh:mm") {
    result = ` ${h < 10 ? "0" + h : h}:${min < 10 ? "0" + min : min}`;
  }
  if (format == "yyyy") {
    result = `${y}`;
  }
  return result;
}
